<?php
namespace Home\Controller;
use Think\Controller;
class MyOfficeController extends CommonController{
	public function way(){
//		$this->redirect("circular");
		session("action","MyOffice");
		session("menu_id",I('get.menu_id',0,'intval'));
		$this->redirect("Public/index");
	}
	
	
	public function circular(){
		$model = M("circular");
		$dept = M("sys_dept");
		$data_dept = $dept->select();
		
		$count = $model->count();
		$page = new \Think\Page($count,15);
		$show = $page->show();
		
		$data = $model->order('create_time desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('data_dept',$data_dept);
		$this->assign('data',$data);
		$this->assign("page",$show);
		$this->display();
	}
	
	public function circular_view(){
		$id = I('get.id');
		$circular = M("circular");
		$data_circular = $circular->where('id=%d',$id)->find();
		$this->assign('data_circular',$data_circular);
		$this->display();
	}
	
	public function attendance(){//指纹考勤
		
		date_default_timezone_set('PRC');
		$time1 = date('Y-m-d');
		$time2 = date('Y-m-d',strtotime('+1 day'));
		$time3 = $_POST['time3']?$_POST['time3']:date('Y-m');
		
		$name = session('name');
		$user = M("Oa_sys_user");
		$user_id = $user->where("name='$name'")->getField('user_id');
		$checkinout = M("Oa_checkinout");
		$checktime = $checkinout->where('user_id='.$user_id." AND date_format(checktime,'%Y-%m')='".$time3."'")->order('checktime desc')->select();
		$days = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
		$list = array();
		$list2 = array();
		foreach ($days as $key=>$value){
			foreach ($checktime as $key1=>$value1){
			$day = date('d',strtotime($value1['checktime']));
				if($value == $day){
					$list[$day][]=$value1['checktime'];//将同一天的数据放到一个数组中
					$list2[]=$day;
				}
			}	
		}
		
		$data = array();
		foreach ($days as $key=>$value){
			if(in_array($value, $list2)){
				foreach ($list as $key2=>$value2){
					if($value == $key2){
						$data[$value][date] = $time3."-".$value;
						$data[$value][starttime] = substr(end($value2),11,5);
						$data[$value][endtime] = substr($value2['0'],11,5);
					}
				}
			}
		}
		$this->assign('data',$data);
		$this->assign('mouth',$time3);
		$this->display();
	}
    
    public function _empty($name){
    	$this->emptyaction($name);
    }
}
?>